////
////  DayReportListViewController.swift
////  BellManage
////
////  Created by Bestsch on 16/4/14.
////  Copyright © 2016年 wsl. All rights reserved.
////
//
//import UIKit
//
//class DayReportListViewController: BaseViewController {
//
//    
//    var tableView: UITableView!
//    
//    override func viewDidLoad() {
//        super.viewDidLoad()
//
//        // Do any additional setup after loading the view.
//        
//        self.title = "铃铛日报"
//        
//        InitViews()
//        
//    }
//    
//    func InitViews() {
//        
//        tableView = UITableView.init(frame: CGRectMake(0, 0, screenW, screenH))
//        tableView.backgroundColor = UIColor.clearColor()
//        tableView.separatorStyle = UITableViewCellSeparatorStyle.None
//        self.view.addSubview(tableView)
//        
//        setUpRefresh()
//    }
//
//    func setUpRefresh() {
//        
//        tableView.mj_header = MJRefreshNormalHeader.init(refreshingTarget: self, refreshingAction: #selector(DayReportListViewController.refresh))
//        tableView.mj_header.beginRefreshing()
//    }
//    
//    func refresh(){
//        let user = getUserPojo()
//        let request = requestHeader + "20</t><sch>" + user.schid + "</sch></channel></rss>"
//        let url = server + adminwebapppi
//        
//        var result = HttpUtils.HttpPostUTF(url, with: request)
//        result = result.stringByReplacingOccurrencesOfString("null", withString: "\"\"")
//        
//        result = "{\"post\":" + result + "}"
//        let dic1: NSDictionary = try! NSJSONSerialization.JSONObjectWithData(result.dataUsingEncoding(NSUTF8StringEncoding)!, options: NSJSONReadingOptions.AllowFragments) as! NSDictionary
//        let array = dic1.objectForKey("post")
//        if array?.count != 0 {
//            for i in 0...(array?.count)! - 1 {
//                                /// 数据库操作
//                let documentsFolder = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
//                let path = documentsFolder.stringByAppendingString("/report.sqlite")
//                print(path)
//                let database = FMDatabase(path: path)
//                
//                if !database.open() {
//                    print("无法打开数据库")
//                }
//                
//                if !database.executeUpdate("create table if not exists dayreport (id integer primary key autoincrement, user text, signuser text, allteacher text, classwork text, classhornor text, notice text, growth text, leave text, editdate text)", withArgumentsInArray: nil){
//                    print("dayreport创建失败")
//                }
//                
//                let dic = array?.objectAtIndex(i) as! NSDictionary
//                
//                let userNum = dic.objectForKey("useNum")?.stringValue//学校当日使用人数（一个用户只计算一次）
//                let useregcon = dic.objectForKey("useregcon")?.stringValue//学校的教师注册用户人数
//                let usercon = dic.objectForKey("usercon")?.stringValue//学校的教师总人数
//                let usernoregcon = dic.objectForKey("UserNoRegCon")?.stringValue//学校未注册教师用户
//                let classactcon = dic.objectForKey("classactcon")?.stringValue//学校当日班级活动发布的数量
//                let honorcon = dic.objectForKey("honorcon")?.stringValue//学校当日班级荣誉发布数量
//                let anncon = dic.objectForKey("AnnCon")?.stringValue//学校当日班级通知发布数量
//                let growthcon = dic.objectForKey("GrowthCon")?.stringValue//学校当日成长记录发布数量
//                let leavecon = dic.objectForKey("LeaveCon")?.stringValue//学校当日请假数量
//                
//                let users = "当日使用人数" + userNum! + "人"
//                let signuser = "注册教师" + useregcon! + "人，未注册教师" + usernoregcon! + "人"
//                let allTeacher = "学校教师总数" + usercon! + "人"
//               
//                
//                
//                let classwork = "班级活动发布" + classactcon! + "次"
//                let classhornor = "班级荣誉发布" + honorcon! + "次"
//                let classnotice = "班级通知发布" + anncon! + "次"
//                let growth = "成长记录发布" + growthcon! + "次"
//                let leave = "今日请假次数" + leavecon! + "人"
//                
//                let format = NSDateFormatter()
//                let formatString = "yyyy年MM月dd日"
//                format.dateFormat = formatString
//                let date = format.stringFromDate(NSDate())
//                    
//                if let rs = database.executeQuery("select * from dayreport where editdate = ?", withArgumentsInArray: [date]) {
//                    if rs.next() {
//                        print("存在数据更新")
//                        if !database.executeUpdate("update dayreport set user = ?, signuser = ?, allteacher = ?, classwork = ?, classhornor = ?, notice = ?, growth = ?, leave = ? where editdate = ? ", withArgumentsInArray: [users, signuser, allTeacher, classwork, classhornor, classnotice, growth, leave, date]) {
//                            print("更新数据库失败")
//                        }
//                    }else{
//                        if !database.executeUpdate("insert into dayreport (user, signuser, allteacher, classwork, classhornor, notice, growth, leave, editdate) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", withArgumentsInArray: [users, signuser, allTeacher, classwork, classhornor, classnotice, growth, leave, date]) {
//                            print("数据库插入失败")
//                        }
//                    }
//                } else {
//                    print("不存在数据")
//                }
//                
//                let rs = database.executeQuery("select * from dayreport order by id limit 0,10", withArgumentsInArray: nil)
//                if rs.next(){
//                    let x = rs.stringForColumn("editdate")
//                    print("user:\(x)")
//                }
//            }
//        }
//        
//        
//        
//        tableView.reloadData()
//        tableView.header.endRefreshing()
//
//    }
//    override func didReceiveMemoryWarning() {
//        super.didReceiveMemoryWarning()
//        // Dispose of any resources that can be recreated.
//    }
//    
//
//    /*
//    // MARK: - Navigation
//
//    // In a storyboard-based application, you will often want to do a little preparation before navigation
//    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
//        // Get the new view controller using segue.destinationViewController.
//        // Pass the selected object to the new view controller.
//    }
//    */
//
//}
